package com.boot.web.controllor.member;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.boot.business.demo.entity.User;
import com.boot.business.demo.service.UserService;


@RestController
@RequestMapping("/users")
@Api(tags={"用户信息1"},value="/users",produces="")
public class UserControllor {
	@Autowired
	private UserService userService;
	
	@ApiOperation(value = "GET请求",notes="注意事项")
	@ApiImplicitParam(dataType = "String",name = "username",value = "用户名",required = true)
	@RequestMapping(method = RequestMethod.GET, value = "/byname")
	@ResponseBody
	public ResponseEntity<Object> list(HttpServletRequest request,String username) {
		System.out.println(username);
		return new ResponseEntity<>(userService.getUserByName(username), HttpStatus.OK);
	}
	
	@ApiOperation(value = "GET请求",notes="根据电话号码 查询用户")
	@ApiImplicitParam(dataType = "String",name = "phone",value = "电话号码",required = true,paramType = "path")
	@RequestMapping(method = RequestMethod.GET, value = "/byusername")
	@ResponseBody
	public ResponseEntity<Object> userlist(HttpServletRequest request,String phone) {
		System.out.println(phone);
		return new ResponseEntity<>(userService.getUserByTelephone(phone), HttpStatus.OK);
	}
	
	@ApiOperation(value = "GET请求",notes="查询所有用户")
	@ApiImplicitParam(dataType = "String",name = "phone",value = "电话号码",required = true,paramType = "path")
	@RequestMapping(value = "/showDao",method = RequestMethod.GET)
	@ResponseBody
	public List<User> showDao(String phone) {
		return userService.showDao(phone);
	}
	
	@ApiOperation(value = "GET请求",notes="新增用户")
	@ApiImplicitParams({
		@ApiImplicitParam(dataType = "String",name = "name",value = "用户信息",required = true,paramType = "path"),
		@ApiImplicitParam(dataType = "string",name = "phone",value = "电话号码",required = true,paramType = "path")
	})
	@RequestMapping(value="/insert",method = RequestMethod.GET)
	@ResponseBody
	public String insert(String name, String phone) {
		return userService.insert(name, phone);
	}
}
